class LoggerSeverity:
    '''Enum-like class that defines logger severities from LS_CRITICAL to LS_DEBUG
    Used by client and services.
    
    May be represented as integer and string (symbolic name of severity used in logging
    and client-service protocols).'''
    
    LS_CRITICAL = 0
    LS_ALERT = 1
    LS_WARNING = 2
    LS_NOTICE = 3
    LS_INFO = 4
    LS_DEBUG = 5
    
    DEFAULT = 4
    
    _names = ['critical', 'alert', 'warn', 'notice', 'info', 'debug']
    
    def __init__(self, ls):
        '''ls may be
            - string - value from LoggerSeverity._names (critical, warn, info, debug, etc.)
            - integer - one of LS_* constants like LoggerSeverity.LS_NOTICE'''
        if isinstance(ls, basestring):
            try:
                ls = self._names.index(ls)
            except ValueError:
                ls = LoggerSeverity.DEFAULT
        
        if LoggerSeverity.LS_CRITICAL <= ls <= LoggerSeverity.LS_DEBUG:
            self.ls = ls
        else:
            self.ls = LoggerSeverity.DEFAULT        
    
    def __cmp__(self, other):
        # Lesser ls value means more critical messages
        cmp = -self.ls.__cmp__(other.ls)
        
        return cmp
    
    def __str__(self):
        return self._names[self.ls]